﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Mayn.Video
{
    public static class HttpHelper
    {
        /// <summary>
        /// 执行POST请求
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="postDataStr"></param>
        /// <returns></returns>
        public static async Task HttpPostAysnc(string Url, string postDataStr = "")
        {
            try
            {
                byte[] postData = Encoding.UTF8.GetBytes(postDataStr);
                WebClient webClient = new WebClient();
                webClient.Headers.Add("Content-Type", "application/json; charset=utf-8");
                webClient.UploadDataTaskAsync(Url, "POST", postData);

            }
            catch (Exception ex)
            {
            }
        }

        /// <summary>
        /// 执行POST请求
        /// </summary>
        /// <param name="Url"></param>
        /// <param name="postDataStr"></param>
        /// <returns></returns>
        public static string HttpPost(string Url, string postDataStr = "")
        {
            string srcString = "";
            try
            {
                byte[] postData = Encoding.UTF8.GetBytes(postDataStr);
                WebClient webClient = new WebClient();
                webClient.Headers.Add("Content-Type", "application/json; charset=utf-8");
                var responseData = webClient.UploadData(Url, "POST", postData);
                srcString = Encoding.UTF8.GetString(responseData);

            }
            catch (Exception ex)
            {
            }
            return srcString;
        }
    }
}
